<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>添加老师</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="<%=basePath%>/layui/css/layui.css" media="all">
  <script src="<%=basePath%>/js/jquery-3.2.1.min.js"></script>
	<script src="<%=basePath%>/js/vue.min.js"></script>
	<script src="<%=basePath%>/layui/layui.js" charset="utf-8"></script>
</head>
<body>
<form class="layui-form">
	<div class="layui-form-item" style="margin-top:50px;">
	    <div class="layui-form-item">
		    <label class="layui-form-label">工号：</label>
		    <div class="layui-input-inline">
			    <input class="layui-input" style="width:300px;" type = "text" id="tno" lay-verify="required" lay-reqtext="账号是必填项！">
			</div>
		</div>
	    <div class="layui-form-item">
		    <label class="layui-form-label">姓名：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="tname" lay-verify="required" lay-reqtext="用户名是必填项！">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">性别：</label>
		    <div class="layui-input-inline">
			   <input type="radio" name="sex" lay-filter="erweima" value="男" title="男" checked>
			   <input type="radio" name="sex" lay-filter="erweima" value="女" title="女" > 
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">密码：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="tPassword">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">系部：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="tDepartment">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">学科：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="tObject">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">学厉：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="tDegree">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">职称：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="tJobs">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">研究方向：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="cDirection">
			</div>
		</div>
	    <div class="layui-form-item">
		    <label class="layui-form-label">邮件：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="email">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">办公室：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="tAddress">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">手机号：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="tPhone">
			</div>
		</div>
	    <div class="layui-form-item" style="margin-left:150px;margin-top:50px;">
			<button type="button" class="layui-btn" lay-submit="" lay-filter="add">添加</button>
			<button type="button" class="layui-btn" onclick="back();">返回</button>
		</div>
 	 </div>
</form>
</body>

<script>

layui.use(['form', 'layedit', 'laydate'], function(){
	var form = layui.form
	,layer = layui.layer
	,layedit = layui.layedit
	,laydate = layui.laydate;

	form.on('submit(add)', function(data){
		var param = new Object();
		param.tno  = $('#tno').val();
		param.tname = $('#tname').val();
		param.sex = $("input[type='radio']:checked").val();
		param.tPassword = $('#tPassword').val();
		param.tDepartment = $('#tDepartment').val();
		param.tObject = $('#tObject').val();
		param.tDegree = $('#tDegree').val();
		param.tJobs = $('#tJobs').val();
		param.cDirection = $('#cDirection').val();
		param.email = $('#email').val();
		param.tAddress = $('#tAddress').val();
		param.tPhone = $('#tPhone').val();
		//全部更新 解决单选框不渲染
		form.render();
		
		 console.log("send message:"+JSON.stringify(param));
		 $.ajax({
				type:"GET",
				url:"/bysjxksys/admin/add_teacher",
				dataType:"json",
				//contentType:"application/json",
		        data:param,
				success: function(data){
					if(data.code==1){
						alert(data.msg);
					}else{
						alert("数据添加成功！");
						//layer.msg("添加用户成功", { icon: 1, time:2000 });
						//layui.msg("添加用户成功！");
						parent.location.reload();
						//window.location.reload();				
					}
				},
				error: function(data, type, err){
					console.log(type);
					console.log(err);
				}
			});
		
	    return false;
	});
});

function back(){
	//当你在iframe页面关闭自身时
    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index);
    window.location.reload();
};

</script>
</html>